<template>
    <div>
        <home-header :city="city"></home-header>
        <home-swiper :list="swiperList"></home-swiper>
        <home-icons :iconList="iconList"></home-icons>
        <home-recommend :recommendList="recommendList"></home-recommend>
        <home-weekend :weekendList="weekendList"></home-weekend>
    </div>
</template> 

<script>
// 引入Header文件
import HomeHeader from './components/Header'
// 引入轮播图文件
import HomeSwiper from './components/Swiper'
// 引入 图标  文件
import HomeIcons from './components/Icons'
// 引入 热销推荐  文件
import HomeRecommend from './components/Recommend'
import HomeWeekend from './components/Weekend'
// 引入axios  发送ajax请求
import axios from 'axios'

export default {
    name: 'Home',
    // 声明局部主键
    components:{
        HomeHeader:HomeHeader,
        HomeSwiper:HomeSwiper,
        HomeIcons:HomeIcons,
        HomeRecommend:HomeRecommend,
        HomeWeekend:HomeWeekend
    },
    data(){
        return {
            city: '',
            swiperList:[],
            iconList:[],
            recommendList:[],
            weekendList:[]
        }
    },
    methods:{
        getHomeInfo(){
            // 挂载页面
            axios.get('/api/index.json')
            // 返回
            .then(this.getHomeInfoSucc)
        },
        // 获取数据
        getHomeInfoSucc(res){
            res=res.data
            if(res.ret && res.data){
                const data=res.data
                this.city=data.city
                this.swiperList=data.swiperList
                this.iconList=data.iconList
                this.recommendList=data.recommendList
                this.weekendList=data.weekendList
            }
            // console.log(res);
        }
    },
    // 生命周期函数
    mounted(){
        this.getHomeInfo()
    }
}
</script>

<style>

</style>
